# coding=utf-8
import requests

print('仅供学习，请勿商用，如有违规，后果自负！')

while True:
    ID = input('请输入音乐ID：')
    url = 'http://music.163.com/song/media/outer/url?id=' + ID
    headers = {
        'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36 Edg/87.0.664.66'
    }
    try:
        music = requests.get(url=url, headers=headers).content
        with open('./music.mp3', 'wb') as file:
            file.write(music)
            print('下载成功！')
    except:
        print('下载失败！')
